<% layout('/layouts/default.html', {title: '信用证管理', libs: ['validate','fileupload','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(letterCredit.isNewRecord ? '新增信用证' : '编辑信用证')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${letterCredit}" action="${ctx}/financial/lettercredit/letterCredit/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="letterCreditId"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="letterCreditCode" maxlength="100" class="form-control" placeholder="自动生成" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('服务订单')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="serviceOrderId" items="${listServiceOrder}"
								itemLabel="serviceOrderCode" itemValue="serviceOrderId" blankOption="true" class="form-control required" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('客户')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:treeselect id="customer" title="${text('客户选择')}"
								path="customer.customerId" labelPath="customer.customerName"
								url="${ctx}/base/customer/customer/treeData" canSelectRoot="true" canSelectParent="true"
								class=" required" allowClear="true" callbackFuncName="customerCallback"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('国内资方')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="investorId" items="${gnzfList}" itemLabel="supplierName" itemValue="supplierId"
								class="form-control required" onchange="investorChange()" blankOption="true"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('外商')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="foreignBusinessmenId" items="${hwzfList}" itemLabel="supplierName" itemValue="supplierId"
								class="form-control required" onchange="foreignBusinessmenChange()" blankOption="true"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('供应商地址')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="supplierAddress" maxlength="255" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('供货外商')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="supplierId" items="${ghwsList}" itemLabel="supplierName" itemValue="supplierId"
								class="form-control required" blankOption="true"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('委托协议')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="entrustAgreement" maxlength="100" class="form-control"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('贸易术语')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="tradeTerm" dictType="trade_term" blankOption="true" class="form-control"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('外贸合同号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="foreignTradeContractNumber" maxlength="100" class="form-control"  readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="form-unit">${text('状态')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('状态')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="orderStatus" dictType="letter_credit_status" blankOption="true" class="form-control"  readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="form-unit">${text('信用证信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('信用证开证日')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="letterCreditIssuanceDate" readonly="true" maxlength="20" class="form-control laydate required"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('信用证号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="letterCreditNumber" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('信用证到期日')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="letterCreditExpiryDate" readonly="true" maxlength="20" class="form-control laydate required"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd" data-done="checkEndDate()"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('开证比例')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="ratio" maxlength="10" class="form-control"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('开证银行')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="bank" dictType="bank" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('信用证总金额')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="totalAmount" class="form-control required number"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('付款方式')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="paymentMethod" dictType="payment_method" blankOption="true" class="form-control"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('最晚装船日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="latestShipmentDate" readonly="true" maxlength="20" class="form-control "
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('装运港')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="fromPort" dictType="erp_harbor_list" blankOption="true" class="form-control"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('目的港')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="toPort" dictType="erp_harbor_list" blankOption="true" class="form-control"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('币种')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="currency" dictType="sys_bizhong" blankOption="true" class="form-control"  readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('是否预投保')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="preInsuredFlag" dictType="sys_yes_no" blankOption="true" class="form-control" />
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注信息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<h4 class="form-unit">${text('车辆信息')}</h4>
				<div class="ml10 mr10">
					<table id="letterCreditDetailDataGrid"></table>
<!--					<% if (hasPermi('financial:lettercredit:letterCredit:edit')){ %>-->
<!--					<a href="#" id="letterCreditDetailDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>-->
<!--					<% } %>-->
				</div>
				<h4 class="form-unit">${text('附件上传')}</h4>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2">
								<span class="required hide">*</span> ${text('附件上传')}：</label>
							<div class="col-sm-10">
								<#form:fileupload id="uploadFile" bizKey="${letterCredit.id}" bizType="letterCredit_file"
								uploadType="all" class="" readonly="false" preview="true"/>
							</div>
						</div>
					</div>
				</div>
				<h4 class="form-unit">${text('版本信息')}</h4>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('版本号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="version" class="form-control digits" readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<h4 class="form-unit">${text('系统信息')}</h4>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('创建者')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="createBy" maxlength="64" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('创建时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="createDate" readonly="true" maxlength="20" class="form-control "
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('更新者')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="updateBy" maxlength="64" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('更新时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="updateDate" readonly="true" maxlength="20" class="form-control"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('financial:lettercredit:letterCredit:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
	function checkEndDate(){
		let startDate=$("#letterCreditIssuanceDate").val();
		let endDate=$("#letterCreditExpiryDate").val();
		if(endDate<=startDate){
			$("#endDate").val('');
			js.showErrorMessage("到期日期不能早于开证日期！");
		}
	}
//初始化信用证明细DataGrid对象
$("#letterCreditDetailDataGrid").dataGrid({

	data: ${toJson(letterCredit.letterCreditDetailList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	columnModel: [
		{header:'主键', name:'letterCreditDetailId', editable:true, hidden:true},
		{header:'${text("车辆")}', name:'tcar.carName', index:'tcar.carName', width:300, editable:false},
		{header:'${text("品牌")}', name:'brand', width:150,
			editable:false, edittype:'select', formatter: function(val, obj, row, act){
				return js.getDictLabel(${@DictUtils.getDictListJson('car_pinpai')}, val, '${text("未知")}', true);
			}
		},
		{header:'${text("版型")}', name:'area', width:150, editable:false, edittype:'text', formatter: function(val, obj, row, act){
				return js.getDictLabel(${@DictUtils.getDictListJson('car_quyu')}, val, '${text("未知")}', true);
		}},
		// {header:'${text("车辆")}', name:'carId', width:300, editable:false, edittype:'select', editoptions:{'maxlength':'64', 'class':'form-control',
		// 		items: ${toJson(tcarList)},
		// 		itemLabel: 'carName', itemValue: 'carId', dataInit: function(element){
		// 			$(element).select2().on("change",function(){
		// 				$(this).resetValid();
		// 			});
		// 		}
		// }},
		{header:'${text("车辆")}', name:'carId', editable:true, hidden:true},
		// {header:'${text("品牌")}', name:'brand', width:200,
		// 	editable:false, edittype:'select', editoptions:{'class':'form-control',
		// 		items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('car_pinpai')}),
		// 		itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
		// 			$(element).select2().on("change",function(){$(this).resetValid()});
		// 		}
		// 	}
		// },
		{header:'${text("品牌")}', name:'brand', editable:true, hidden:true},
		// {header:'${text("版型")}', name:'area', width:200, editable:false, edittype:'select', editoptions:{'class':'form-control',
		// 		items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('car_quyu')}),
		// 		itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
		// 			$(element).select2().on("change",function(){$(this).resetValid()});
		// 		}
		// 	}
		// },
		{header:'${text("版型")}', name:'area', editable:true, hidden:true},
		{header:'${text("车型")}', name:'model', width:200, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control', 'readonly':'true'}},
		{header:'${text("数量")}', name:'quantity', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control digits', 'readonly':'true'}},
		{header:'${text("单价")}', name:'unitPrice', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number', 'readonly':'true'}},
		{header:'${text("车辆总价")}', name:'amount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number', 'readonly':'true'}},
		{header:'${text("押汇金额")}', name:'negotiatedAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number', 'readonly':'true'}},
		// {header:'${text("状态")}', name:'status1', width:150,
		// 	editable:false, edittype:'select', editoptions:{'class':'form-control',
		// 		items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('letter_credit_detail_status')}),
		// 		itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
		// 			$(element).select2().on("change",function(){$(this).resetValid()});
		// 		}
		// 	}
		// },
		{header:'${text("状态")}', name:'status1', width:100,
			editable:false, edittype:'select', formatter: function(val, obj, row, act){
				return js.getDictLabel(${@DictUtils.getDictListJson('letter_credit_detail_status')}, val, '${text("未知")}', true);
			}
		},
		{header:'${text("状态")}', name:'status1', editable:true, hidden:true},
		{header:'${text("信用证ID")}', name:'letterCreditId.letterCreditId', editable:true, hidden:true},
		{header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
			var actions = [];
				actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#letterCreditDetailDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
			return actions.join('');
		}, editoptions: {defaultValue: 'new'}}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	// editGridAddRowBtn: $('#letterCreditDetailDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {letterCreditDetailId: ''},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'letterCreditDetailList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,letterCreditDetailId,carId,brand,area,model,quantity,unitPrice,amount,negotiatedAmount,status1,letterCreditId.letterCreditId,', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
</script>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
</script>